package com.itheima.exer.homework.hw1007.hwtest;


import com.itheima.exer.homework.hw1007.domain.Student;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ToMapDemo {
    public static void main(String[] args) {
        List<Student> students = List.of(new Student("张三", 23, 100),
                new Student("张思睿", 23, 77),
                new Student("张三丰", 23, 89),
                //new Student("张三丰", 23, 89),
                new Student("李小璐", 23, 99),
                new Student("贾乃亮", 23, 56));
        /*Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int i = o1.getScore() - o2.getScore();
                return i;
            }
        });
        System.out.println(students);*/
        Map<String, Integer> map = students.stream().distinct().collect(Collectors.toMap(s -> s.getName(), s -> s.getScore()));
        System.out.println(map);
        Map<String, Integer> collect = students.stream().distinct().collect(Collectors.toMap(new Function<Student, String>() {
            @Override
            public String apply(Student student) {
                return student.getName();
            }
        }, new Function<Student, Integer>() {
            @Override
            public Integer apply(Student student) {
                return student.getScore();
            }
        }));
        System.out.println(collect);
    }
}
